/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Andro.Med;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.List;
import modele.DAO;
import modele.Med;

/**
 *
 * @author elo
 */
public class AutreActivity extends ListActivity {

    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.autrevue);
        TextView label = (TextView) findViewById(R.id.label);
        Intent inter = getIntent();
        String dep = inter.getStringExtra("leDep");
        label.setText(dep);

        final List<Med> lesMed = DAO.getLesMed(dep);
        MedAdapter adapter = new MedAdapter(lesMed, this);
        setListAdapter(adapter);

        Button button = (Button) findViewById(R.id.buttonFiltre);
        final EditText EditText = (EditText) findViewById(R.id.TextFiltre);

        button.setOnClickListener(new OnClickListener() {

            public void onClick(View arg0) {

                List<Med> lesMedF = new ArrayList<Med>();
                for (Med unMed : lesMed) {
                    if (unMed.getNom().startsWith(EditText.getText().toString())) {
                        lesMedF.add(unMed);
                    }
                }
                MedAdapter adapter = new MedAdapter(lesMedF, getApplicationContext());
                setListAdapter(adapter);
            }
        });

    }

}
